import { defineStore } from "pinia";

export const useSystemStore = defineStore({
    id: "system",
    state: () => ({
        theme: localStorage.getItem("darkTheme") ? true : false,
        loading: false,
    }),
    getters: {
        sysTheme() {
            return this.theme;
        },
    },
    actions: {
        //切换主题
        toggleTheme() {
            if (!this.theme) localStorage.setItem("darkTheme", "yes");
            else localStorage.setItem("darkTheme", null);
            this.theme = !this.theme;
        },

        setLoading(val) {
            this.$patch({
                loading: val,
            });
        },
    },
});
